package com.ruoyi.auth.mq;

import com.ruoyi.auth.domain.SmsMessage;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class SmsProducer {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    //声明队列
    @Bean
    public Queue queue1(){
        return QueueBuilder.durable("q1").ttl(10000).build();
    }
    //声明交换机
    @Bean
    public DirectExchange directExchange1() {
        return new DirectExchange("exchange1");
    }
    //绑定队列和交换机
    @Bean
    public Binding binding(DirectExchange directExchange1, Queue queue1) {
        return BindingBuilder.bind(queue1).to(directExchange1).with("a");
    }
    public void sendMsg(SmsMessage smsMessage) {
        rabbitTemplate.convertAndSend("exchange1", "a", smsMessage);
    }



}
